package com.example.sy2.demos.web.controller;

import com.example.sy2.demos.web.entity.Grade;
import com.example.sy2.demos.web.entity.Student;
import com.example.sy2.demos.web.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/students")
public class StudentController {
    @Autowired
    private StudentService studentService;

    @GetMapping("/listAll")
    public ResponseEntity<List<Student>> listAll() {
        return ResponseEntity.ok(studentService.listAllStudents());
    }

    @GetMapping("/getById/{studentId}")
    public ResponseEntity<Student> getById(@PathVariable Long studentId) {
        return ResponseEntity.ok(studentService.getStudentById(studentId));
    }

    @GetMapping("/getGrades/{studentId}")
    public ResponseEntity<List<Grade>> getGrades(@PathVariable Long studentId) {
        return ResponseEntity.ok(studentService.getGradesByStudentId(studentId));
    }

    @PostMapping("/add")
    public ResponseEntity<Void> add(@RequestBody Student student) {
        studentService.addStudent(student);
        return ResponseEntity.ok().build();
    }
}